#!/usr/bin/env node

/**
 * 测试日志同步功能的脚本
 * 用于验证sync-logs-to-notion.js脚本的各种功能
 */

const fs = require('fs');
const path = require('path');

// 确保logs目录存在
const logsDir = path.join(__dirname, '..', 'logs');
if (!fs.existsSync(logsDir)) {
  fs.mkdirSync(logsDir);
}

// 创建测试日志文件
const testLogs = {
  'development.log': [
    '{"level":"info","timestamp":"2025-11-03T10:00:00.000Z","message":"Application initialized","service":"main","label":"startup"}',
    '{"level":"info","timestamp":"2025-11-03T10:01:00.000Z","message":"Winston logger module removed","service":"logger","label":"cleanup"}',
    '2025-11-25T08:30:00.000Z [info] [github] GitHub logging system integrated',
    '2025-11-25T08:31:00.000Z [info] [notion] Notion logging system integrated'
  ],
  'error.log': [
    '{"level":"error","timestamp":"2025-11-25T08:22:56.729Z","message":"Database connection failed","service":"database","label":"connection"}',
    '2025-11-25T08:23:00.000Z [error] [main] 这是error级别的日志'
  ],
  'http.log': [
    '{"level":"info","timestamp":"2025-11-16T05:02:55.000Z","message":"GET /api/test 200 15ms","service":"http","label":"request"}',
    '2025-11-16T05:03:00.000Z [info] [http] 这是一条信息日志 { "user": "test", "ip": "127.0.0.1" }'
  ]
};

// 写入测试日志文件
Object.keys(testLogs).forEach(logFile => {
  const filePath = path.join(logsDir, logFile);
  fs.writeFileSync(filePath, testLogs[logFile].join('\n') + '\n');
  console.log(`Created test log file: ${filePath}`);
});

console.log('Test log files created successfully!');
console.log('You can now run the sync script with:');
console.log('node scripts/sync-logs-to-notion.js');